
 <!-- START DATATABLE 2 -->
<div class="row">
	<div class="col-lg-12">
		<?php if($panel): ?>
		<div class="panel panel-default">
			<div class="panel-heading"><?php echo @$header_title; ?></div>
			<div class="panel-body">
		<?php endif; ?>
				<table id="<?php echo $config['table_name'] ?>" class="table table-striped table-hover"  cellspacing="0" width="100%">
					<thead>
						<tr>
						<?php foreach($header as $head_value) {
							$attr = "";
							foreach((array)@$head_value['attr'] as $hk => $hv)
								$attr .= "$hk=\"$hv\" ";
							if(isset($head_value['type'])) {
								echo "<th type=\"{$head_value['type']}\"><input type=\"{$head_value['type']}\"  {$attr} /></th>";
							} else echo "<th {$attr}>{$head_value['name']}</th>";
						} ?>
						</tr>
						<tr class="filter-row gc-search-row">
						<?php foreach($header as $head_value) {
							$attr = "";
							foreach((array)@$head_value['attr'] as $hk => $hv)
								$attr .= "$hk=\"$hv\" ";
							if(isset($head_value['type'])) {
								echo "<th type=\"{$head_value['type']}\"><input type=\"{$head_value['type']}\"  {$attr} /></th>";
							} else echo "<th {$attr}>{$head_value['name']}</th>";
						} ?>
						</tr>
					</thead>
			 
					
				</table>
		<?php if($panel): ?>
			</div>
		</div>
		<?php endif; ?>
	</div>
</div>
 <!-- START DATATABLE 2 -->
<script type="text/javascript">
$(document).ready(function() {

	$('#<?php echo $config['table_name'] ?> thead tr.filter-row th').each( function () {
		var th = $('#<?php echo $config['table_name'] ?> thead tr.filter-row th').eq( $(this).index() );
		var type = th.attr('type');
		if(type === undefined) {
			var title = th.text();
			if(title != '')
			{
				$(this).html( '<input type="text" class="form-control" placeholder="Search '+title+'" style="max-width: 100%;width: 100%;" />' );
			}
		}
    } );
	
    var dttable = $('#<?php echo $config['table_name'] ?>').DataTable( {
		dom: '<"top"fl>rt<"bottom"pi><"clear">',
		processing: true,
        serverSide: true,
        "bSortCellsTop": true,
        ajax: <?php echo json_encode($config['ajax']); ?>,
        language: {
            url: "<?php echo admin_theme_url();?>js/Vietnamese.json"
        },
         "bStateSave": true,
         "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {
         	var primary_key = aData.<?php echo @$this->{$this->model}->primary_key;?>;
		    $(nRow).attr("id",'' + primary_key);
		    return nRow;
  		},
        fnInitComplete: function(oSettings, oData) {
        	<?php if($showAdd) { ?> 
		     $("div.top").append('<a href="<?php echo $this->url_add;?>" class="btn btn-default" style="margin-left: 10px;"><i class="fa fa-plus"></i> Thêm mới</button></a>');
		     <?php }?>
    },
		aoColumnDefs: <?php echo json_encode($format_cols); ?>
    } );
	
	// var dttable = $('#<?php echo $config['table_name'] ?>').DataTable();
	
	dttable.columns().eq( 0 ).each( function ( colIdx ) {
		var th = $('#<?php echo $config['table_name'] ?> thead tr.filter-row th').eq( colIdx );
        $( 'input[type=text]', th ).on( 'keyup change', function () {
            dttable
                .column( colIdx )
                .search( this.value )
                .draw();
        } );
    } );

	$('body').on( 'click', '.edit-click',function () {
        var data = dttable.row( $(this).parents('tr') ).data();
        var primary_key = data.<?php echo $this->{$this->model}->primary_key;?>;
        window.location.href = "<?php echo $this->url_edit;?>"+primary_key;
    } );
$('body').on( 'click', '.delete-row',function () {
        var data = dttable.row( $(this).parents('tr') ).data();
        var primary_key = data.<?php echo $this->{$this->model}->primary_key;?>;
        url = "<?php echo $this->url_delete;?>"+primary_key;
        $(".input_url_delete").val(url);
		$(".input_id_delete").val(primary_key);
    } );

	<?php foreach($config['action'] as $conf_k => $conf_v) { ?>
	$(document).on('<?php echo $conf_k ?>', '<?php echo $conf_v["object"]; ?>', function(){
		<?php echo $conf_v['func']."();"; ?>
	});
	<?php } ?>
});

</script>
<script type="text/javascript">


</script>
